<?php
namespace Android\Model;


class HolidayModel extends BaseModel {

    /**
     * 获取指定学生的请假信息
     *
     * @param $student_id
     */
    public function getHolidayBySid($student_id) {
        $result = $this->field('stime,etime,title,content,status,response')->where('student_id = '.$student_id)->order('stime desc')->find();
        if (empty($result))
            return null;
        return $result;
    }


    /**
     * 更具指定条件查找请假条
     *
     * @param $where
     * @param string $limit
     * @return mixed|null
     */
    public function getHolidayByWhere($where,$limit='') {

        empty($where) && $where='';
        $result = $this->where($where)->limit($limit)->order('status asc, addtime desc')->select();
        return $result;
    }


    public function handlerHoliday($data) {
        return $this->save($data);
    }



    public function getStudentId($id) {
        return $this->where('id = ' . $id)->getField('student_id');
    }



    public function addHoliday($data) {
        return $this->add($data);
    }


    public function getStudentHoliday($student_id, $term_id, $limit = '') {

        $result = $this->table("__HOLIDAY__ holiday, __TEACHER__ teacher")
                       ->field("holiday.id,holiday.title,holiday.content,holiday.stime,holiday.etime,holiday.status,holiday.response,teacher.name AS teacher_name")
                       ->where("holiday.student_id = {$student_id} AND holiday.term_id = {$term_id} AND holiday.teacher_id = teacher.id")
                       ->limit($limit)
                       ->select();

        return $result;

    }


}